﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;

using Kwan.Data;
using BG.Data;

namespace BG.Service
{
    public class CustomerQuery
	{

		public static Expression MakeSearchWhere(NameValueCollection ps)
		{
			Expression exp = new Expression();

            string propName = "EntityID";
            if (!string.IsNullOrEmpty(ps[propName]))
                exp &= TCustomer.entityID == int.Parse(ps[propName]);

			propName = "address";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.address == ps[propName];
			}
			propName = "bankCard";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.bankCard == ps[propName];
			}
			propName = "country";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.country == ps[propName];
			}
			propName = "iDNO";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.iDNO == ps[propName];
			}
			propName = "iDType";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.iDType == int.Parse(ps[propName]);
			}
			propName = "level";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.level == int.Parse(ps[propName]);
			}
			propName = "memo";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.memo == ps[propName];
			}
			propName = "nameCN";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
                exp &= TCustomer.nameCN.Like("%" + ps[propName] + "%");
			}
			propName = "nameEN";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.nameEN == ps[propName];
			}
			propName = "phone";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.phone == ps[propName];
			}
			propName = "sex";
			if (!string.IsNullOrEmpty(ps[propName]))
			{
				exp &= TCustomer.sex == int.Parse(ps[propName]);
			}

            propName = "orderID";   //nameCN,OrderID
			if (!string.IsNullOrEmpty(ps[propName]))
			{
                exp &= VCustomer.orderID > 0;
			}
            

			return exp;
		}
	}
}